package com.livesource.client.web.liveTaskBoard;

import java.util.HashMap;

import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.livesource.client.model.entry.ProjectClass;
import com.livesource.client.model.entry.ProjectFeature;
import com.livesource.client.utilities.LoadingPanel;

/**
 * 
 * @UserInterface
 */
public class BoardPanel extends VerticalPanel {

	private static VerticalPanel vpNotStarted = new VerticalPanel();
	private static VerticalPanel vpInProgress = new VerticalPanel();
	private static VerticalPanel vpDone = new VerticalPanel();
	private static VerticalPanel vpError = new VerticalPanel();

	public BoardPanel() {

		HorizontalPanel hpTitles = new HorizontalPanel();

		Label space2 = new Label(" ");
		space2.setWidth("70px");
		hpTitles.add(space2);

		HTML htmlNotStarted = new HTML("<B>To Do</B>");
		htmlNotStarted.setWidth("250px");
		hpTitles.add(htmlNotStarted);

		HTML htmlBlocked = new HTML("<B>Error</B>");
		htmlBlocked.setWidth("250px");
		hpTitles.add(htmlBlocked);

		HTML htmlInProgress = new HTML("<B>In Progress</B>");
		htmlInProgress.setWidth("250px");
		hpTitles.add(htmlInProgress);

		HTML htmlDone = new HTML("<B>Done</B>");
		htmlDone.setWidth("250px");
		hpTitles.add(htmlDone);

		this.add(hpTitles);

		HorizontalPanel hpBoard = new HorizontalPanel();

		vpNotStarted.setSpacing(15);
		vpNotStarted.setWidth("250px");
		vpNotStarted.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		vpNotStarted
				.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		hpBoard.add(vpNotStarted);

		VerticalPanel vpSeparation1 = new VerticalPanel();
		vpSeparation1.setSize("1px", "500px");
		vpSeparation1.setStyleName("taskBoard");
		vpSeparation1.add(new Label(" "));
		hpBoard.add(vpSeparation1);

		vpError.setSpacing(15);
		vpError.setWidth("250px");
		vpError.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		vpError.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		hpBoard.add(vpError);

		VerticalPanel vpSeparation3 = new VerticalPanel();
		vpSeparation3.setSize("1px", "500px");
		vpSeparation3.setStyleName("taskBoard");
		vpSeparation3.add(new Label(" "));
		hpBoard.add(vpSeparation3);

		vpInProgress.setSpacing(15);
		vpInProgress.setWidth("250px");
		vpInProgress.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		vpInProgress
				.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		vpInProgress.add(new LoadingPanel());

		hpBoard.add(vpInProgress);

		VerticalPanel vpSeparation2 = new VerticalPanel();
		vpSeparation2.setSize("1px", "500px");
		vpSeparation2.setStyleName("taskBoard");
		vpSeparation2.add(new Label(" "));
		hpBoard.add(vpSeparation2);

		vpDone.setSpacing(15);
		vpDone.setWidth("250px");
		vpDone.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
		vpDone.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		hpBoard.add(vpDone);

		this.add(hpBoard);
	}

	public static void showTasks(HashMap<String, ProjectClass> entries) {

		vpNotStarted.clear();
		vpError.clear();
		vpInProgress.clear();
		vpDone.clear();

		if (entries != null) {

			for (ProjectClass entry : entries.values()) {

				if (ProjectFeature.TODO_STATUS.equals(entry.getStatus())) {

					vpNotStarted.add(new TaskPanel(entry));

				} else if (ProjectFeature.ERROR_STATUS
						.equals(entry.getStatus())) {

					vpError.add(new TaskPanel(entry));

				} else if (ProjectFeature.INPROGRESS_STATUS.equals(entry
						.getStatus())) {

					vpInProgress.add(new TaskPanel(entry));

				} else if (ProjectFeature.FEATURE_TYPE.equals(entry
						.getFeatureType())) {

					vpDone.add(new TaskPanel(entry));

				}
			}

		}
	}
}
